
layui.config({
	base: basePath, 
	version: skyeyeVersion
}).extend({
    window: 'js/winui.window'
}).define(['window', 'jquery', 'winui'], function (exports) {
	winui.renderColor();
	var index = parent.layer.getFrameIndex(window.name);
	var $ = layui.$,
		form = layui.form;

	var wagesFieldTypeListHtml = '';
	AjaxPostUtil.request({url: sysMainMation.wagesBasePath + "queryEnableWagesFieldTypeList", params: {}, type: 'json', method: "POST", callback: function (json) {
		wagesFieldTypeListHtml = getDataUseHandlebars(`<option value="">全部</option>{{#each rows}}<option value="{{id}}">{{name}}({{id}})</option>{{/each}}`, json);
	}, async: false});

	showGrid({
		id: "showForm",
		url: reqBasePath + "companyjobscore003",
		params: {id: parent.rowId},
		pagination: false,
		method: "GET",
		template: $("#beanTemplate").html(),
		ajaxSendLoadBefore: function(hdb) {
		},
		ajaxSendAfter:function (json) {
			skyeyeClassEnumUtil.showEnumDataListByClassName("commonEnable", 'radio', "enabled", json.bean.enabled, form);

			initTable();
			initTableChooseUtil.deleteAllRow('fieldList');
			$.each(json.bean.scoreFields, function(i, item) {
				item['fieldMation'] = {
					id: item.fieldKey,
					name: item.fieldName + '(' + item.fieldKey + ')',
				}
				initTableChooseUtil.resetData('fieldList', item);
			});

			matchingLanguage();
			form.render();
			form.on('submit(formEditBean)', function (data) {
				if (winui.verifyForm(data.elem)) {
					var result = initTableChooseUtil.getDataList('fieldList');
					if (!result.checkResult) {
						return false;
					}
					var tableData = [].concat(result.dataList);
					var params = {
						name: $("#name").val(),
						jobId: parent.jobId,
						enabled: $("#enabled input:radio:checked").val(),
						scoreFields: JSON.stringify(tableData),
						id: parent.rowId,
				};
					AjaxPostUtil.request({url: reqBasePath + "writeCompanyJobScoreMation", params: params, type: 'json', method: "POST", callback: function (json) {
						parent.layer.close(index);
						parent.refreshCode = '0';
					}});
				}
				return false;
			});
		}
	});

	function initTable() {
		initTableChooseUtil.initTable({
			id: "fieldList",
			cols: [
				{id: 'fieldKey', title: '字段', formType: 'select', width: '150', verify: 'required', modelHtml: wagesFieldTypeListHtml},
				{id: 'minMoney', title: '最小薪资范围', formType: 'input', width: '100', verify: 'required|money', value: '0'},
				{id: 'maxMoney', title: '最大薪资范围', formType: 'input', width: '100', verify: 'required|money', value: '0'},
				{id: 'remark', title: '备注', formType: 'input', width: '100'}
			],
			deleteRowCallback: function (trcusid) {
			},
			addRowCallback: function (trcusid) {
			},
			form: form
		});
	}

	$("body").on("click", "#cancle", function() {
		parent.layer.close(index);
	});
});